from django.shortcuts import render
from .models import Article, Category, Tag, Keyword, FriendLink


# Create your views here.
def index(request):
    """主页"""
    article_lst = Article.objects.filter(is_published=True, is_top=True).order_by('-topic_order')
    return render(request, 'blog/index.html', {'article_lst': article_lst})


def about(request):
    """关于"""
    return render(request, 'blog/about.html')


def contact(request):
    """联系"""
    return render(request, 'blog/contact.html')


def articles(request):
    """文章"""
    article_lst = Article.objects.filter(is_published=True)
    return render(request, 'blog/articles.html', {'article_lst': article_lst})


def articles_detail(request, slug):
    """文章详情"""
    article = Article.objects.get(slug=slug)
    article.update_views()
    return render(request, 'blog/detail.html', {'article': article})


def subject_list(request):
    """专题列表"""
    return render(request, 'blog/subject_list.html')


def subject_page(request, pk):
    """专题详情"""

    return render(request, 'blog/subject_page.html')


def subject_detail(request):
    """专题文章内容"""
    return render(request, 'blog/subject_detail.html')


def friend_link(request):
    """友链"""
    friend_lst = FriendLink.objects.filter(is_active=True)
    return render(request, 'blog/friend_link.html', {'friend_lst': friend_lst})